<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @property float $child_price 儿童价
 * @property float $deposit 押金
 * @property float $price 成人价
 * @property float $reward 返佣金额
 * @property float $score 评分
 * @property int $id
 * @property int $line_id 所属线路
 * @property int $sales 销量
 * @property string $crowd 人群说明
 * @property string $description 产品说明
 * @property string $detail 产品介绍
 * @property string $expense 费用须知
 * @property string $images 图片
 * @property string $line_tag_ids 标签
 * @property string $name 景点名称
 * @property string $rerule 退改规则
 * @property-read \app\model\LineOrdersAssess[] $assess
 * @property-read \app\model\LineSpotStops[] $stop
 * @property-read \app\model\UserCollect $user_collect
 * @property-read mixed $images_text
 * @property-read mixed $line_id_text
 * @property-read mixed $line_tag_ids_text
 * @mixin \think\Model
 */
class LineSpot extends Model
{
    protected $append = [
		'line_tag_ids_text',
	    'images_text'
    ];
	
	function getLineTagIdsTextAttr($value,$data)
	{
		$ling_tag_ids = $value ?? ($data['line_tag_ids'] ?? '');
		return LineTags::whereIn('id',$ling_tag_ids)->column('name');
	}
	
	function getImagesTextAttr($value,$data)
	{
		$value = $value ?? ($data['images'] ?? '');
		return $value?explode(',', $value):[];
	}
	
	public function getLineIdTextAttr($value, $data)
	{
		$value = $value ? $value : ($data['line_id'] ?? '');
		$list = ['1' => '会员路线', '2' => '推荐路线', '3' => '火爆路线'];
		return $list[$value] ?? '';
	}
	
	function stop()
	{
		return $this->hasMany(LineSpotStops::class,'spot_id');
	}
	
	public function userCollect()
	{
		return $this->hasOne(UserCollect::class,'spot_id');
	}
	
	function assess()
	{
		return $this->hasMany(LineOrdersAssess::class,'spot_id');
	}
	
}
